package com.eric.windows.imgDispose;

import android.app.Activity;
import android.graphics.BitmapFactory;
import android.graphics.BitmapShader;
import android.graphics.Color;
import android.graphics.ComposeShader;
import android.graphics.LinearGradient;
import android.graphics.PorterDuff;
import android.graphics.RadialGradient;
import android.graphics.Shader;
import android.graphics.SweepGradient;
import android.view.View;

import com.eric.windows.R;
import com.eric.windows.imgDispose.views.ShaderView;

import org.androidannotations.annotations.AfterInject;
import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;

@EActivity(R.layout.activity_shader_test)
public class ShaderTestActivity extends Activity {

    @ViewById(R.id.shader_view)
    ShaderView shaderView;

    private int[] colors;
    private Shader[] shaders = new  Shader[5];

    @AfterViews
    void initData(){
        colors = new int[]{Color.RED,Color.GREEN,Color.BLUE};
        shaders[0] = new BitmapShader(BitmapFactory.decodeResource(getResources(),R.mipmap.pic_2),
                Shader.TileMode.REPEAT, Shader.TileMode.MIRROR);
        shaders[1] = new LinearGradient(0,0,100,100,colors,null, Shader.TileMode.REPEAT);
        shaders[2] = new RadialGradient(100,100,80,colors,null, Shader.TileMode.REPEAT);
        shaders[3] = new SweepGradient(160,160,colors,null);
        shaders[4] = new ComposeShader(shaders[0],shaders[1], PorterDuff.Mode.DARKEN);
    }

    @AfterInject
    void setData(){

    }

    @Click({R.id.btn_shader_bitmap,R.id.btn_shader_linear,
            R.id.btn_shader_radial,R.id.btn_shader_sweep,R.id.btn_shader_compose})
    public void onClick(View view){
        switch (view.getId()){
            case R.id.btn_shader_bitmap:
                shaderView.paint.setShader(shaders[0]);
//                shaderView.paint.setAlpha(1);
                break;
            case R.id.btn_shader_linear:
                shaderView.paint.setShader(shaders[1]);
//                shaderView.paint.setAlpha(100);
                break;
            case R.id.btn_shader_radial:
                shaderView.paint.setShader(shaders[2]);
//                shaderView.paint.setAlpha(255);
                break;
            case R.id.btn_shader_sweep:
                shaderView.paint.setShader(shaders[3]);
                break;
            case R.id.btn_shader_compose:
                shaderView.paint.setShader(shaders[4]);
                break;

        }
        shaderView.invalidate();
    }
}
